<template>
  <div class="exams-container">
    <!-- 学员信息头部 -->
    <div class="student-header">
      <h1>考试信息</h1>
      <div class="student-info">
        <span class="name">张明</span>
        <span class="divider">·</span>
        <span class="license-type">C1驾照</span>
        <span class="divider">·</span>
        <span class="student-id">学员编号：2023112233</span>
      </div>
    </div>

    <!-- 考试进度 -->
    <div class="section">
      <h2>考试进度</h2>
      <div class="progress-grid">
        <div v-for="subject in subjects" :key="subject.name"
             :class="['progress-item', subject.status]">
          <span class="subject-name">{{ subject.name }}</span>
          <span class="subject-status">{{ subject.statusText }}</span>
          <span v-if="subject.score" class="subject-score">{{ subject.score }}分</span>
          <span v-if="subject.date" class="subject-date">{{ subject.date }}</span>
        </div>
      </div>
    </div>

    <!-- 近期考试安排 -->
    <div class="section">
      <h2>近期考试安排</h2>
      <div class="exam-table">
        <div class="table-header">
          <span>考试科目</span>
          <span>考试时间</span>
          <span>考试地点</span>
          <span>状态</span>
          <span>操作</span>
        </div>
        <div class="table-row" v-for="exam in upcomingExams" :key="exam.id">
          <span>{{ exam.subject }}</span>
          <span>{{ exam.time }}</span>
          <span>{{ exam.location }}</span>
          <span :class="['status', exam.status]">{{ exam.statusText }}</span>
          <span class="action" @click="viewDetail(exam.id)">查看详情</span>
        </div>
      </div>
    </div>

    <!-- 历史考试记录 -->
    <div class="section">
      <h2>历史考试记录</h2>
      <div class="exam-table">
        <div class="table-header">
          <span>考试科目</span>
          <span>考试时间</span>
          <span>考试地点</span>
          <span>考试成绩</span>
          <span>状态</span>
        </div>
        <div class="table-row" v-for="record in historyRecords" :key="record.id">
          <span>{{ record.subject }}</span>
          <span>{{ record.time }}</span>
          <span>{{ record.location }}</span>
          <span>{{ record.score }}分</span>
          <span :class="['status', record.status]">{{ record.statusText }}</span>
        </div>
      </div>
    </div>

    <!-- 考试须知 -->
    <div class="section notice-section">
      <h2>考试须知</h2>
      <ul class="notice-list">
        <li v-for="(notice, index) in examNotices" :key="index">{{ notice }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 考试科目数据
const subjects = ref([
  { name: '科目一', status: 'passed', statusText: '已通过', score: '92', date: '2024-02-15' },
  { name: '科目二', status: 'pending', statusText: '待考试' },
  { name: '科目三', status: 'not-started', statusText: '未开始' },
  { name: '科目四', status: 'not-started', statusText: '未开始' }
])

// 近期考试安排
const upcomingExams = ref([
  {
    id: 1,
    subject: '科目二',
    time: '2024-02-15 09:00',
    location: '考场A',
    status: 'pending',
    statusText: '待考试'
  }
])

// 历史考试记录
const historyRecords = ref([
  {
    id: 1,
    subject: '科目一',
    time: '2024-01-10 14:30',
    location: '考场B',
    score: '92',
    status: 'passed',
    statusText: '通过'
  }
])

// 考试须知
const examNotices = ref([
  '请提前30分钟到达考场，携带身份证、准考证等有效证件',
  '考试当天请穿戴整洁，不得携带通讯设备进入考场',
  '考试过程中请严格遵守考场纪律，如有作弊行为将取消考试资格'
])

const viewDetail = (examId) => {
  router.push(`/exams/${examId}`) // 假设有详情页路由
}
</script>

<style scoped>
.exams-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Microsoft YaHei', sans-serif;
}

.student-header {
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.student-header h1 {
  margin: 0 0 10px 0;
  color: #333;
}

.student-info {
  font-size: 16px;
  color: #666;
}

.student-info .divider {
  margin: 0 8px;
  color: #999;
}

.section {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px dashed #eee;
}

.section h2 {
  margin: 0 0 15px 0;
  color: #333;
  font-size: 18px;
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.progress-item {
  padding: 12px;
  border-radius: 6px;
  background: #f8f8f8;
  text-align: center;
}

.progress-item.passed {
  background: #e8f5e9;
  border-left: 4px solid #4caf50;
}

.progress-item.pending {
  background: #fff8e1;
  border-left: 4px solid #ffc107;
}

.progress-item.not-started {
  background: #f5f5f5;
  border-left: 4px solid #9e9e9e;
}

.subject-name {
  display: block;
  font-weight: bold;
  margin-bottom: 5px;
}

.subject-status {
  display: block;
  color: #666;
  margin-bottom: 5px;
}

.subject-score, .subject-date {
  display: block;
  font-size: 14px;
  color: #888;
}

.exam-table {
  border: 1px solid #eee;
  border-radius: 6px;
  overflow: hidden;
}

.table-header, .table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 0.8fr 0.8fr;
  padding: 12px 15px;
  align-items: center;
}

.table-header {
  background: #f5f5f5;
  font-weight: bold;
  color: #333;
}

.table-row {
  border-top: 1px solid #eee;
}

.table-row:hover {
  background: #f9f9f9;
}

.status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
}

.status.passed {
  background: #e8f5e9;
  color: #2e7d32;
}

.status.pending {
  background: #fff8e1;
  color: #ff8f00;
}

.action {
  color: #1976d2;
  cursor: pointer;
  text-decoration: underline;
}

.notice-section {
  border-bottom: none;
}

.notice-list {
  padding-left: 20px;
  color: #666;
}

.notice-list li {
  margin-bottom: 10px;
  line-height: 1.6;
}
</style>
